package com.lemons.hackaton.app.data;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.sun.xml.xsom.XSAttributeDecl;
import com.sun.xml.xsom.XSComplexType;
import com.sun.xml.xsom.XSElementDecl;
import com.sun.xml.xsom.XSSchema;
import com.sun.xml.xsom.XSSchemaSet;
import com.sun.xml.xsom.parser.XSOMParser;

public class XSDSchemaParser {

	public void parseSchema(String path) {

		File file = new File("D:\\data\\journey.xsd");
		try {
			XSOMParser parser = new XSOMParser();
			parser.parse(file);
			XSSchemaSet sset = parser.getResult();
			XSSchema mys = sset.getSchema(1);
			Iterator itr = sset.iterateSchema();
			while (itr.hasNext()) {
				XSSchema s = (XSSchema) itr.next();
				//System.out.println("Target namespace: " + s.getTargetNamespace());
				XSComplexType ct = mys.getComplexType("journeyType");
				int ctr = 0;
				if (ct != null) {
					Iterator i = ct.iterateDeclaredAttributeUses();
					while (i.hasNext()) {
						
						XSAttributeDecl attributeDecl = (XSAttributeDecl) i.next();
						

//						System.out.print("ctr=" + ctr++ + "name:" + attributeDecl.getName());
//						System.out.print("    type: " + attributeDecl.getType());
//						System.out.println("");
					}
				}
				Iterator jtr = s.iterateElementDecls();
				while (jtr.hasNext()) {
					XSElementDecl e = (XSElementDecl) jtr.next();

//					System.out.print(e.getName());
//					if (e.isAbstract())
//						System.out.print(" (abstract)");
//					System.out.println();
				}
			}
		} catch (Exception exp) {
			exp.printStackTrace(System.out);
		}

	}

}
